﻿#region 信息

// Copyright©2014 Rex Rao all rights reserved.
// File name : SoMcCoffee\Sohobloo.SoCommon\LogInitializer.cs
// Author : Sohobloo
// Create time : 2014/02/01 23:58
// Update time : 2014/02/05 8:53

#endregion

#region 引用

using log4net;
using log4net.Config;
using log4net.Core;

#endregion

namespace Sohobloo.SoCommon.Log
{
    public static class LogInitializer
    {
        public static void Initialize(bool enableTraceSql = true)
        {
            var commonRespository = LogManager.CreateRepository("SoCommon.Logger");
            var errorAppender = new Appender(Level.Error);
            var infoAppender = new Appender(Level.Info);
            var debugAppender = new Appender(Level.Debug);
            BasicConfigurator.Configure(commonRespository, errorAppender, infoAppender, debugAppender);
            Logger.CommonLogger = LogManager.GetLogger(commonRespository.Name, commonRespository.Name);

            if(enableTraceSql)
            {
                var sqlRespository = LogManager.CreateRepository("SoCommon.SqlTracer");
                var sqlAppender = new Appender(Level.Debug, "SQLTrace");
                BasicConfigurator.Configure(sqlRespository, sqlAppender);
                Logger.SqlTracer = LogManager.GetLogger(sqlRespository.Name, sqlRespository.Name);
            }
        }
    }
}